package me.zhengjie.minbearwcs.dao.config.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import me.zhengjie.minbearwcs.dao.config.inf.HttpConfigDao;
import me.zhengjie.minbearwcs.entity.Mapper.config.HttpConfigMapper;
import me.zhengjie.minbearwcs.entity.PO.config.HttpConfig;

@Repository
@RequiredArgsConstructor
public class HttpConfigDaoImpl implements HttpConfigDao {

    private final HttpConfigMapper mapper;

    @Override
    public HttpConfig selectByHttpName(String name) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(HttpConfig::getConfigName,name)
                .oneOpt()
                .orElse(null);

    }

    @Override
    public boolean insert(HttpConfig httpConfig) {
        return mapper.insert(httpConfig) == 1;
    }

    @Override
    public boolean updateByHttpName(String name, String httpUrl) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(HttpConfig::getConfigName,name)
                .set(HttpConfig::getConfigIp,httpUrl)
                .update();
    }
}
